﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports System.Linq
Imports GenDotNet.TemplateSupport
Imports GenDotNet.Task.Common

Public Class ConstructorInfo
   Inherits MemberInfo

   Private mConstructorDelegate As EmptyDelegate
   Private mBaseParameters As ParameterInfoCollection

   Public Sub New( _
            ByVal typeInfo As TypeInfo, _
            ByVal scope As Scope, _
            ByVal methodDelegate As EmptyDelegate, _
            ByVal ParamArray parameters() As ParameterInfo)
      MyBase.New(Nothing, typeInfo, scope, Nothing, parameters)
      Me.mConstructorDelegate = methodDelegate
      Me.mBaseParameters = New ParameterInfoCollection
   End Sub

   Public Property ConstructorDelegate() As EmptyDelegate
      Get
         Return mConstructorDelegate
      End Get
      Set(ByVal value As EmptyDelegate)
         mConstructorDelegate = value
      End Set
   End Property

   Public ReadOnly Property BaseParameters() As ParameterInfoCollection
      Get
         Return Me.mBaseParameters
      End Get
   End Property
End Class


Namespace VB
   Public Module ConstructorInfoExtensions

      <Runtime.CompilerServices.Extension()> _
      Public Function Output( _
               ByVal info As ConstructorInfo) _
               As String
         Return <code>
                   <%= info.Scope.Output %> Sub New(<%= info.Parameters.Output %>)
   <%= If(info.BaseParameters Is Nothing OrElse info.BaseParameters.Count = 0, String.Empty, _
      <code>
      MyBase.New(<%= info.BaseParameters.OutputForCall %>)
      </code>.Value) %>
                   <%= info.ConstructorDelegate.Invoke() %>
   End Sub
</code>.Value
      End Function

   End Module
End Namespace

Namespace CSharp
   Public Module ConstructorInfoExtensions
      <Runtime.CompilerServices.Extension()> _
      Public Function Output( _
               ByVal info As ConstructorInfo) _
               As String
         Return <code>
                   <%= info.Scope.Output.WithSpace %><%= info.TypeInfo.Name %>(<%= info.Parameters.Output %>)
   <%= If(info.BaseParameters Is Nothing OrElse info.BaseParameters.Count = 0, String.Empty, _
      <code>
      : base(<%= info.BaseParameters.OutputForCall %>)
      </code>.Value) %>
      {
       <%= info.ConstructorDelegate.Invoke().WithSemiColons %>
      }
</code>.Value
      End Function

   End Module
End Namespace
